package cn.itcast.controller;

import cn.itcast.domain.vo.MessageVO;
import org.springframework.ai.chat.memory.ChatMemoryRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ai/history")
public class ChatHistoryController {
    @Autowired
    private ChatMemoryRepository chatMemoryRepository;
    @GetMapping("/{type}")
    public List<String> getHistory(@PathVariable String type){
        List<String> conversationIds = chatMemoryRepository.findConversationIds();
        return conversationIds;
    }

    @GetMapping("/{type}/{chatId}")
    public List<MessageVO> getHistoryList(@PathVariable String type, @PathVariable String chatId){
        List<MessageVO> list = chatMemoryRepository.findByConversationId(chatId).stream().map(message -> new MessageVO(message)).toList();
        return list;
    }
}
